package reload

import (
	"gddgame.cc/galaxy"
	"gddgame.cc/galaxy/asteroid"
	"gddgame.cc/galaxy/binocle/logic"
)

func bindReload(subscriber asteroid.Sub) {
	subscriber.On("reload", func(message asteroid.Message) {
		galaxy.Exit()
	})
}

type Reloader interface {
	Reload(observer string, node string)
}
type reload struct {
	watcher *logic.WatcherInstance
}

func newReload(watcher *logic.WatcherInstance) *reload {
	r := &reload{
		watcher: watcher,
	}

	return r
}

func (r *reload) Reload(observer string, node string) {
	publisher := r.watcher.Observing(observer)
	if publisher != nil {
		publisher.Direct(node).Send("reload")
	}
}
